home *** CD-ROM | disk | FTP | other *** search
- Path: newshost.lanl.gov!tanmoy
- From: tanmoy@qcd.lanl.gov (Tanmoy Bhattacharya)
- Newsgroups: comp.lang.c
- Subject: Re: Newbie: How to return Multi-Dimensional Array's?
- Date: 08 Feb 1996 15:29:07 GMT
- Organization: Los Alamos National Laboratory
- Message-ID: <TANMOY.96Feb8082907@qcd.lanl.gov>
- References: <4f7t4m$4bk@news.xs4all.nl> <3118B3F7.2781E494@nada.kth.se>
- NNTP-Posting-Host: qcd.lanl.gov
- Mime-Version: 1.0
- Content-Type: text
- In-reply-to: Fredrik Rubensson's message of Wed, 07 Feb 1996 15:15:19 +0100
-
- In article <3118B3F7.2781E494@nada.kth.se> Fredrik Rubensson
- <prgp-fru@nada.kth.se> writes:
- <snip>
- > char *foo()
- > {
- > char arr[10][5];
- > // do something
- > return (arr)
- > }
-
- A multidimensional char-array is represented as an array of
- char-pointers so the return type of foo should be char**. The
- parenthesis around arr after return are not needed.
-
- Please read the FAQ: the post uncovers a very serious
- misunderstanding. A multidimensional array, like the one declared
- above is _not_ an array of char pointers. In other words, char
- arr[10][5] is different from char *arr[10] or [5]. It is true that the
- multidimensional array does not decay into a pinter to char, but
- neither does it decay into char**.
-
- In short: char arr[10][5] means that arr is the name of a region of
- memory which consists of 10 contiguos regions, each region consisting
- of 5 contiguous regions capable of storing chars. sizeof(arr) is thus
- guaranteed to be 50. It contains no storage for any pointers. When
- used in any context other than being an immediate operand of & and
- sizeof, it decays into a pointer to the first region: which is a
- pointer to an array of 5 chars, i.e. char(*)[5]. Note that again, the
- region that this points to stores no pointer!
-
- char ** is a pointer to a region which stores a pointer to a char. Is
- it obvious that the two are different?
-
- Cheers
- Tanmoy
- --
- tanmoy@qcd.lanl.gov(128.165.23.46) DECNET: BETA::"tanmoy@lanl.gov"(1.218=1242)
- Tanmoy Bhattacharya O:T-8(MS B285)LANL,NM87545 H:#9,3000,Trinity Drive,NM87544
- Others see <gopher://yaleinfo.yale.edu:7700/00/Internet-People/internet-mail>,
- <http://alpha.acast.nova.edu/cgi-bin/inmgq.pl>or<ftp://csd4.csd.uwm.edu/pub/
- internetwork-mail-guide>. -- <http://nqcd.lanl.gov/people/tanmoy/tanmoy.html>
- fax: 1 (505) 665 3003 voice: 1 (505) 665 4733 [ Home: 1 (505) 662 5596 ]
-